var mainModule = angular.module('main', ['ui.router', 'ngResource', 'ngSanitize','w5c.validator']);
mainModule.run(function($rootScope, $state, $http, $stateParams, $location,$timeout,$window) {
	$rootScope.$state = $state;
	$rootScope.$stateParams = $stateParams;
});

// mainModule.config(['$stateProvider','$urlRouterProvider',function($stateProvider,$urlRouterProvider) {
// 	$stateProvider.state('found',{
// 		url : '/test1',
// 		templateUrl : '../test1'
// 	}).state('test2',{
// 		url : '/guanzhu',
// 		templateUrl : '../test2'
// 	})
// }])

/*
 * 活动页面
 */
var ActivityPage={
	astatus:1,
	init:function() {
		ActivityPage.queryActivity();
		ActivityPage.activityOption();
		$(".J_newActivity").unbind('click').bind('click', function () {
			$(".J_rightContent").html("<div style='color:cornflowerblue;'>创建活动!!!!</div>");
		});
		$('#J_query_activity').unbind('click').bind('click', function () {
			ActivityPage.queryActivity();
		});
	},
	activityOption:function(){
		$(".activityStatus").click(function(){
			var _this = $(this);
			_this.addClass("active").siblings().removeClass("active");
			ActivityPage.astatus = _this.index();
			ActivityPage.queryActivity();
		});
	},
	queryActivity:function(){
		$(".J_activityList").html('');
		var activity_name = $('#J_activity_name').val();
		var data={};
		data.currentPage = 1;
		data.pageSize = 10;
		if(ActivityPage.astatus > 0){
			data.activity_status = ActivityPage.astatus;
		}
		if(activity_name){
			data.activity_name = activity_name;
		}
		$.ajax({
			method : 'post',
			url : '/queryActivity.action',
			data:data
		}).success(function(resp){
			console.log(resp.status);
			if(resp.status===0 || resp.status===2){
				var result = resp.result.data;
				var html='<div class="create">'+
					'<div class="icon"></div>'+
					'<div class="text">创建活动</div>'+
					'<a href="/createActivity" target="_blank" class="J_newActivity"></a>'+
					'</div>';
				if(result){
					// 组装模板数据
					// var html = new EJS({url: 'activityPageTemplate.ejs'}).render(data);
					// var html = JS.Tools.template('activitylistTemp',data);
					for(var i=0; i<result.length; i++) {
						html +='<div class="placeholder">'+
									'<div class="placeholder-img">'+
									'<img  src="http://sjbz.fd.zol-img.com.cn/t_s320x510c/g5/M00/09/0A/ChMkJlhRE56IaK2lAAjhaFie8_cAAYjWgJq_DQACOGA390.jpg">'+
									'<span class="l"><a href="/activity?aid='+result[i].activity_id+'" target="_blank">预览</a></span> <span class="r"><a href="/createActivity?aid='+result[i].activity_id+'" target="_blank">编辑</a></span>'+
									'</div>'+
									'<div class="name">'+result[i].activity_name+' <span class="glyphicon glyphicon-trash"></span></div>'+
									'<span class="last-time">最后修改时间: '+result[i].activity_ctime.substring(0,10)+'</span>'+
								'</div>';
					}
				}
				//window.location.href="../home";
			}else{
				alert(resp.message);
			}
			$(".J_activityList").html(html);
		}).error(function() {
			console.log('系统异常');
		});
	}
};
$(function(){
	ActivityPage.init();
});
